package observer;

import java.util.ArrayList;

public class WeatherData implements Subject {
    private final ArrayList<Observer> observers;
    private float temperature;
    private float humidity;
    private float pressure;

    public WeatherData() {
        observers = new ArrayList<>();
    }

    @Override
    public void registerObserve(Observer o) {
        observers.add(o);
    }

    @Override
    public void removeObserve(Observer o) {
        observers.remove(o);
    }

    @Override
    public void notifyObserves() {
        observers.forEach(observer -> observer.update(temperature, humidity, pressure));
    }

    //温度
    public float getTemperature() {
        return this.temperature;
    }

    //湿度
    public float getHumidity() {
        return this.humidity;
    }

    //压力
    public float getPressure() {
        return this.pressure;
    }

    public void measurementsChanged() {
        notifyObserves();
    }

    public void setMeasurements(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        measurementsChanged();
    }
}
